﻿using aier.business.logic;
using aier.dataaccess.model;
using aier.dataaccess.dapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using log4net;

namespace aier.wx.api.selfhost.Controllers
{
    [Authorize]
    [RoutePrefix("api/Department")]
    public class DepartmentController : ApiController
    {
        public ILog log { get; set; }
        public DepartmentBll departmentBll { get; set; }
        /// <summary>
        /// 根据医院和科室名称(可空)获取科室
        /// </summary>
        /// <param name="hospitalId"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        [HttpGet]
        [Authorize]
        [ActionName("GetDepartmentsByHospID")]
        public IHttpActionResult GetDepartmentsByHospID(string hospitalId,string name)
        {
           
            try
            {
                if (!string.IsNullOrWhiteSpace(hospitalId))
                {
                    var departments = departmentBll.GetDepartmentsByHospID(new Guid(hospitalId),name);
                    return Ok(departments);
                }

                return NotFound();
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                return new ApiErrorResult(ex.Message, Request);

            }
        }

        [HttpGet]
        [ActionName("GetDepartmentByHospitalId")]
        public IHttpActionResult GetDepartmentByHospitalId(Guid hospitalId)
        {
            var data = departmentBll.GetDepartmentByHospitalId(hospitalId);

            return Ok(data);
        }
    }
}
